package com.tcm.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.tcm.config.AppProperties;
import com.tcm.entity.Image;
import com.tcm.entity.dto.param.ImageUpdateParam;
import com.tcm.entity.dto.ImageUploadDto;
import com.tcm.entity.vo.ImageListResult;
import com.tcm.entity.resp.PageR;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author Guqier
 * @version 1.0
 * @date 2023/7/2 17:13
 */
public interface ImageService extends IService<Image> {


    @Transactional
    List<Image> uploadBatch(List<ImageUploadDto> imageUploadDtos, Long currUserId);

    PageR<ImageListResult> getImageListByPage(Integer pageNum, Integer pageSize, Integer type, String name, List<Long> imageIds);

    @Transactional
    boolean modifyImageInfo(ImageUpdateParam imageInfo, Long currUserId);

    @Transactional
    boolean removeImage(List<Long> ids, Long currUserId) throws Exception;

    Map<String, String> uploadSingle(ImageUploadDto imageUploadDto, Long currUserId) throws Exception;

    List<Image> getImagesByItemId(Long itemId);

    @Cacheable(value = AppProperties.ENTITY_CACHE_IMAGE, key = "#id", unless = "#result == null")
    Image getImageById(Long id);

    @CacheEvict(value = AppProperties.ENTITY_CACHE_IMAGE, key = "#id", condition = "#id != null")
    boolean removeImageById(Long id);
}
